/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * semestre_unidad.java
 *
 * Created on 06-oct-2011, 13:58:27
 */

package proyectocatalina.mantenimiento;

import CapadeDatos.daosemestreunidad;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import modelo.beansemestre;
import modelo.beanunidad;
import modelo.beanunidad2;

/**
 *
 * @author jxtx
 */
public class semestre_unidad extends javax.swing.JInternalFrame {

    /** Creates new form semestre_unidad */
    public semestre_unidad() {
        initComponents();
          this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
       
        ActionEvent e = null;
        if(newsemestreunidad.cod==null || newsemestreunidad.cod.equals("no habido") ){
        

        }else{ jtxtcodsem.setText(newsemestreunidad.cod );
        jbtnsemActionPerformed( e );}

    }
static String coddelistado;
static int y;

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane3 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jtxtobservacion = new javax.swing.JTextField();
        jbtnagreagaruni = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jtxtcoduni = new javax.swing.JTextField();
        jbtnbuscaruni = new javax.swing.JButton();
        jbtntodauni = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtable2 = new javax.swing.JTable();
        jLabel10 = new javax.swing.JLabel();
        jbtnquitaruni = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtable1 = new javax.swing.JTable();
        jLabel13 = new javax.swing.JLabel();
        jtxtestado = new javax.swing.JTextField();
        jbtnchangeestado = new javax.swing.JButton();
        jtxtfin = new javax.swing.JTextField();
        jbtnsem = new javax.swing.JButton();
        jtxtcodsem = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jtxtini = new javax.swing.JTextField();
        jtxtcarr = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jtxtsem = new javax.swing.JTextField();
        jtxtperlect = new javax.swing.JTextField();
        jtxtturno = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jbtnveralumnos = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        jPanel1.setEnabled(false);

        jLabel9.setText("observacion:");

        jbtnagreagaruni.setText("CONFIRMAR NUEVA UNIDAD AL SEMESTRE");
        jbtnagreagaruni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnagreagaruniActionPerformed(evt);
            }
        });

        jLabel8.setText("Buscar una unidad --->codigo unidad :");

        jbtnbuscaruni.setText("Buscar");
        jbtnbuscaruni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnbuscaruniActionPerformed(evt);
            }
        });

        jbtntodauni.setText("Mostrar lista de Unidades");
        jbtntodauni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtntodauniActionPerformed(evt);
            }
        });

        jtable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "UNIDAD", "MODULO", "DESCRIPCION UNIDAD", "DESCRIPCION  MODULO"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtable2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jtable2FocusGained(evt);
            }
        });
        jScrollPane2.setViewportView(jtable2);

        jLabel10.setText("SELECCIONE UNA UNIDAD DE PARA QUE SE A REMOVIDA:");

        jbtnquitaruni.setText("QUITAR UNIDAD DE SEMESTRE");
        jbtnquitaruni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnquitaruniActionPerformed(evt);
            }
        });

        jLabel2.setText("UNIDADES PODRIA TENER:");

        jLabel1.setText("UNIDADES TIENE :");

        jtable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "UNIDAD", "MODULO", "DESCRIPCION UNIDAD", "DESCRIPCION  MODULO"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtable1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jtable1FocusGained(evt);
            }
        });
        jScrollPane1.setViewportView(jtable1);

        jLabel13.setText("Estado:");

        jtxtestado.setEnabled(false);

        jbtnchangeestado.setText("Cambiar de Estado");
        jbtnchangeestado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnchangeestadoActionPerformed(evt);
            }
        });

        jtxtfin.setEnabled(false);

        jbtnsem.setText("Buscar semestre");
        jbtnsem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnsemActionPerformed(evt);
            }
        });

        jtxtcodsem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtcodsemActionPerformed(evt);
            }
        });
        jtxtcodsem.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jtxtcodsemFocusGained(evt);
            }
        });

        jLabel11.setText("Fecha de Inicio:");

        jtxtini.setEnabled(false);

        jtxtcarr.setEnabled(false);

        jLabel3.setText("CODIGO SEMESTRE:");

        jLabel12.setText("Fecha de Fin:");

        jtxtsem.setEnabled(false);

        jtxtperlect.setEnabled(false);

        jtxtturno.setEnabled(false);

        jLabel6.setText("PER. LECTIVO :");

        jLabel7.setText("TURNO :");

        jLabel5.setText("SEMESTRE :");

        jLabel4.setText("CARRERA :");

        jbtnveralumnos.setText("Ver Alumnos");
        jbtnveralumnos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnveralumnosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jtxtcodsem, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jbtnsem)
                                .addGap(58, 58, 58)
                                .addComponent(jbtnveralumnos, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(589, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel11)
                            .addComponent(jLabel13))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jtxtestado, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jbtnchangeestado, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jtxtsem)
                                        .addComponent(jtxtcarr, javax.swing.GroupLayout.PREFERRED_SIZE, 410, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jtxtini, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel12)
                                        .addGap(18, 18, 18)
                                        .addComponent(jtxtfin, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(2, 2, 2)
                                        .addComponent(jLabel6))
                                    .addComponent(jLabel7))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtxtturno)
                                    .addComponent(jtxtperlect, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap(221, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap(912, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addContainerGap(719, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jbtnquitaruni, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)
                        .addGap(595, 595, 595))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addContainerGap(870, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)
                        .addComponent(jtxtcoduni, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnbuscaruni)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtntodauni, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(290, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jbtnagreagaruni, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jtxtobservacion, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(488, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 960, Short.MAX_VALUE))
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtcodsem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnsem)
                    .addComponent(jbtnveralumnos))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtcarr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtsem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtini, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)
                            .addComponent(jtxtfin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel13))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jtxtestado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jbtnchangeestado)))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtperlect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtturno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))))
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtnquitaruni)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jtxtcoduni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnbuscaruni)
                    .addComponent(jbtntodauni))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtobservacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jbtnagreagaruni, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPane3.setViewportView(jPanel1);

        getContentPane().add(jScrollPane3);

        pack();
    }// </editor-fold>//GEN-END:initComponents

  beanunidad2[] detalles;
beanunidad2[] detalles2;

    private void jbtnsemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnsemActionPerformed



        beansemestre semestre=new beansemestre();//recipiente de la info de alumno
ArrayList unidades=new ArrayList();//recipiente de  array
ArrayList unidadesposibles=new ArrayList();//recipiente de array

        String cod=jtxtcodsem.getText();//el codigo

     semestre= (beansemestre)daosemestreunidad.semestre(cod);//recoger datos de alum

     unidades = (ArrayList)daosemestreunidad.unidadestiene(cod);//recoger array de semestre q estuvo
 unidadesposibles = (ArrayList)daosemestreunidad.unidadespodriatener(cod);//recoger array de semestre q puede estar

     jtxtcarr.setText(semestre.getCod_carrera());//mostar info de sem

     jtxtperlect.setText(semestre.getCod_per());

    jtxtsem.setText(semestre.getDescipcion()) ;
     jtxtturno.setText(semestre.getTurno());
     jtxtini.setText(semestre.getFechaini());
     jtxtfin.setText(semestre.getFechafin());
     jtxtestado.setText(semestre.getEstado());
      detalles = new beanunidad2[unidades.size()];//armado y llenado de la 1º tabla que se llama jtable2
          Iterator itr = unidades.iterator();
      int j=0;

      DefaultTableModel dtm = null;

//JOptionPane.showMessageDialog(null," "+detalles[0].getCod_carrera()+"  "+detalles[0].getCod_sem());

dtm =(DefaultTableModel) jtable1.getModel();
      for (int i = jtable1.getRowCount() -1; i >= 0; i--){
dtm.removeRow(i);
}//borrar las lineas de tabla para
//la prox que llame a este codigo
           while (itr.hasNext()) {
          detalles[j] =  (beanunidad2)itr.next();
          Object[] newRow={detalles[j].getUnidad(),detalles[j].getModulo(),
          detalles[j].getUnidaddescripcion(),
          detalles[j].getModulodescripcion()};
           dtm =(DefaultTableModel) jtable1.getModel(); // Obtenemos el modelo por defecto de la tabla
           dtm.addRow(newRow); // añadimos la fila
          j++;
      }

      jtable1.setModel(dtm);

   detalles2 = new beanunidad2[unidadesposibles.size()];//armado y llenado de la 2º tabla se llama jtable1
          Iterator itr2 = unidadesposibles.iterator();
      int k=0;

      DefaultTableModel dtm2 = null;
dtm2 =(DefaultTableModel) jtable2.getModel();
      for (int i = jtable2.getRowCount() -1; i >= 0; i--){//borrar las lineas de tabla para
               dtm2.removeRow(i);
}                                                   //la prox que llame a este codigo

           while (itr2.hasNext()) {
          detalles2[k] =  (beanunidad2)itr2.next();
          Object[] newRow={detalles2[k].getUnidad(),detalles2[k].getModulo(),
          detalles2[k].getUnidaddescripcion(),
            detalles2[k].getModulodescripcion()};
           dtm2 =(DefaultTableModel) jtable2.getModel(); // Obtenemos el modelo por defecto de la tabla
           dtm2.addRow(newRow); // añadimos la fila
          k++;
      }
      jtable2.setModel(dtm2);

       jbtnchangeestado.setEnabled(true);
       jbtnveralumnos.setEnabled(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_jbtnsemActionPerformed






    private void jbtnbuscaruniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnbuscaruniActionPerformed

       beanunidad2 unidad=new beanunidad2();
     String x="x";

       String cod_uni=jtxtcoduni.getText();
if(cod_uni.length()!=0)
{
int k=0;
 unidad=daosemestreunidad.unidad(cod_uni);
if (unidad.getCod_unidad().equals(x) ){
       detalles2 = new beanunidad2[1];//armado y llenado de la 2º tabla se llama jtable1
      

JOptionPane.showMessageDialog(null,"Codigo Incorrecto");

}
else{
      DefaultTableModel dtm2 = null;
dtm2 =(DefaultTableModel) jtable2.getModel();
      for (int i = jtable2.getRowCount() -1; i >= 0; i--){//borrar las lineas de tabla para
               dtm2.removeRow(i);
}                                                   //la prox que llame a este codigo


          detalles2[k] =  (beanunidad2)unidad;
          Object[] newRow={detalles2[k].getUnidad(),detalles2[k].getModulo(),
          detalles2[k].getUnidaddescripcion(),
            detalles2[k].getModulodescripcion()};
           dtm2 =(DefaultTableModel) jtable2.getModel(); // Obtenemos el modelo por defecto de la tabla
           dtm2.addRow(newRow); // añadimos la fila
          k++;

      jtable2.setModel(dtm2);}
       }else
        JOptionPane.showMessageDialog(null," DEBE INGRESAR UN CODIGO PARA BUSCAR");
        // TODO add your handling code here:
    }//GEN-LAST:event_jbtnbuscaruniActionPerformed

    private void jtxtcodsemFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtxtcodsemFocusGained
jbtnagreagaruni.setEnabled(false);
jbtnquitaruni.setEnabled(false);
jbtnchangeestado.setEnabled(false);
jbtnveralumnos.setEnabled(false);

// TODO add your handling code here:
    }//GEN-LAST:event_jtxtcodsemFocusGained

    private void jtable2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtable2FocusGained
jbtnagreagaruni.setEnabled(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jtable2FocusGained

    private void jbtnagreagaruniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnagreagaruniActionPerformed
String coduni,codsem;
String observacion;
ActionEvent e = null;
int j=jtable2.getSelectedRow();

if(j == -1 || jtxtcodsem.getText()==null )
 jbtnagreagaruni.setEnabled(false);
else
 {
        coduni=detalles2[jtable2.getSelectedRow()].getCod_unidad();
            codsem=jtxtcodsem.getText();
        observacion=jtxtobservacion.getText();

        JOptionPane.showMessageDialog(null," "+codsem+"  "+coduni);

    CapadeDatos.daosemestreunidad h = new daosemestreunidad();

      h.insertarunidadsemestre(coduni,codsem,observacion);

      jbtnsemActionPerformed( e );
        }         // TODO add your handling code here:
    }//GEN-LAST:event_jbtnagreagaruniActionPerformed

    private void jtxtcodsemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtcodsemActionPerformed


        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtcodsemActionPerformed

    private void jbtnquitaruniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnquitaruniActionPerformed
String coduni,codsem,nombreunid;
ActionEvent e = null;
int r,j=jtable1.getSelectedRow();
if(j == -1 || jtxtcodsem.getText()==null )
 jbtnquitaruni.setEnabled(false);
else
 {
coduni=detalles[jtable1.getSelectedRow()].getCod_unidad();
            codsem=jtxtcodsem.getText();
            nombreunid=detalles[jtable1.getSelectedRow()].getUnidad();

r=JOptionPane.showConfirmDialog(null,"CONFIRMAR","Esta seguro"
        + " que desea quitar"
        + " la unidad "+nombreunid ,JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
   
if (r==0)
{
    CapadeDatos.daosemestreunidad h = new daosemestreunidad();

      h.borarunidad_semestre(codsem,coduni);
JOptionPane.showMessageDialog(null,"BORRAR "+ coduni+"    "+codsem);

      jbtnsemActionPerformed( e );
        }
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jbtnquitaruniActionPerformed

    private void jtable1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtable1FocusGained
jbtnquitaruni.setEnabled(true);

        // TODO add your handling code here:
    }//GEN-LAST:event_jtable1FocusGained

    private void jbtntodauniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtntodauniActionPerformed



          new listadeunidades().setVisible(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_jbtntodauniActionPerformed

    private void jbtnchangeestadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnchangeestadoActionPerformed
beansemestre semestre;
        String cod_sem;
        String estado;
        cod_sem=jtxtcodsem.getText();
        estado=jtxtestado.getText();
        CapadeDatos.daosemestreunidad k =new daosemestreunidad ();

        k.cambiarestadosemestre(cod_sem,estado);


  semestre= (beansemestre)daosemestreunidad.semestre(cod_sem);//recoger datos de alum

   jtxtestado.setText(semestre.getEstado());


        // TODO add your handling code here:
    }//GEN-LAST:event_jbtnchangeestadoActionPerformed

    private void jbtnveralumnosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnveralumnosActionPerformed


  coddelistado=jtxtcodsem.getText();
y=2;
          new alumnosdesemestre().setVisible(true);


        // TODO add your handling code here:
    }//GEN-LAST:event_jbtnveralumnosActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new semestre_unidad().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton jbtnagreagaruni;
    private javax.swing.JButton jbtnbuscaruni;
    private javax.swing.JButton jbtnchangeestado;
    private javax.swing.JButton jbtnquitaruni;
    private javax.swing.JButton jbtnsem;
    private javax.swing.JButton jbtntodauni;
    private javax.swing.JButton jbtnveralumnos;
    private javax.swing.JTable jtable1;
    private javax.swing.JTable jtable2;
    private javax.swing.JTextField jtxtcarr;
    private javax.swing.JTextField jtxtcodsem;
    private javax.swing.JTextField jtxtcoduni;
    private javax.swing.JTextField jtxtestado;
    private javax.swing.JTextField jtxtfin;
    private javax.swing.JTextField jtxtini;
    private javax.swing.JTextField jtxtobservacion;
    private javax.swing.JTextField jtxtperlect;
    private javax.swing.JTextField jtxtsem;
    private javax.swing.JTextField jtxtturno;
    // End of variables declaration//GEN-END:variables

}
